/*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* Alternatively, this software may be distributed under the terms of BSD
* license.
*
*
*
* Authors:                  zhoujian
* Email:            343600434@qq.com
* Date:         Jan-10-2024 10:19:23
*
*/


#ifndef __input_H__
#define __input_H__

#include "led.h"
#include "device.h"

#ifdef __cplusplus
extern "C" {
#endif

extern uint8_t is_off;

typedef struct {
    //0£º¹Ø±Õ£¬1£º¿ªÆô
    uint8_t Left;
    uint8_t Front_fog_light;
    uint8_t High_beam;
    uint8_t Width_indicator;
    uint8_t Rear_fog_light;
    uint8_t Oil_tips;
    uint8_t Right;
    uint8_t Handbrake;
    uint8_t motor;
    uint8_t Double_flash;
} Car_indicators;



#define DIANCHI_IN


//#define BL_CTRL_OUT gpio_mode_set(GPIOC, GPIO_MODE_OUTPUT,GPIO_PUPD_NONE,GPIO_PIN_7)

#define BL_CTRL_ON do{  gpio_mode_set(GPIOC, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_7);\
                        gpio_output_options_set(GPIOC, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_7);\
                        gpio_bit_set(GPIOC, GPIO_PIN_7); \
                    }while(0)

#define BL_CTRL_OFF do{ gpio_mode_set(GPIOC, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_7);\
                        gpio_output_options_set(GPIOC, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_7);\
                        gpio_bit_reset(GPIOC, GPIO_PIN_7); \
                    }while(0)

#define BL_PWM_CTRL_ON

/*#define DIANMENSUO_IN gpio_mode_set(GPIOC, GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO_PIN_5)
//gpio_mode_set(GPIOB, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, GPIO_PIN_12)
#define JIYOU_IN    gpio_mode_set(GPIOB, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, GPIO_PIN_14)
#define YINGING_IN gpio_mode_set(GPIOB, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, GPIO_PIN_14)
#define ONE_IN gpio_mode_set(GPIOC, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, GPIO_PIN_4)
#define TWO_IN gpio_mode_set(GPIOA, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, GPIO_PIN_7)
#define THREE_IN gpio_mode_set(GPIOA, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, GPIO_PIN_6)
#define FOUR_IN gpio_mode_set(GPIOA, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, GPIO_PIN_5)
#define FIVE_IN gpio_mode_set(GPIOA, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, GPIO_PIN_4)
#define N_IN gpio_mode_set(GPIOD, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, GPIO_PIN_9)
#define P_IN gpio_mode_set(GPIOD, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, GPIO_PIN_8)

#define SHIKUO_IN
//gpio_mode_set(GPIOC, GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO_PIN_5)
#define WUDENG_IN
//gpio_mode_set(GPIOB, GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO_PIN_0)
#define DAOCHE_IN
*/
//gpio_mode_set(GPIOB, GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO_PIN_2)
#define YOUZHUAN_IN gpio_mode_set(GPIOA, GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO_PIN_3)
#define ZUOZHUAN_IN gpio_mode_set(GPIOA, GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO_PIN_4)
#define DADENG_IN gpio_mode_set(GPIOA, GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO_PIN_5)
//#define ABS_IN gpio_mode_set(GPIOC, GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO_PIN_6)


//#define CHECK_INPUT_ACC

#ifndef CHECK_INPUT_ACC
//#warning("no check acc")

#endif
void wait_acc(void);
void input_acc_check(void);

void input_init();
void input_handle(void);

#define GEAR_ON     do{ \
                 }while(0)
#define GEAR_OFF        do{ \
                     }while(0)

#define GEAR_1_ON   do{\
                    }while(0)

#define GEAR_2_ON   do{\
                    }while(0)
#define GEAR_3_ON   do{     \
                    }while(0)
#define GEAR_4_ON   do{ \
         }while(0)

#define GEAR_5_ON   do{ \
                }while(0)

#define GEAR_6_ON   do{ \
                    }while(0)

#define GEAR_N_ON  do{  \
                    }while(0)
#define GEAR_N_OFF  do{  \
                    }while(0)

#define GEAR_X_OFF  do{ \
                    }while(0)



#define GEAR_x_ON(x) GEAR_##x##_ON


#define LOW_POWER_ON    do{ \
        LED_ON(99);    \
            }while(0)
#ifdef LINURM_DEBUG_DIS_RATE_AND_SPEED
#define LOW_POWER_OFF

#else

#define LOW_POWER_OFF   do{ \
            LED_OFF(99);   \
            }while(0)
#endif
#define ECU_ERROR_ON  do{ \
            LED_ON(105);    \
                }while(0)
#ifdef LINURM_DEBUG_DIS_RATE_AND_SPEED
#define ECU_ERROR_OFF

#else
#define ECU_ERROR_OFF     do{ \
                LED_OFF(105);   \
                    }while(0)

#endif

#define MOTOR_ERROR_ON     do{ \
                            LED_ON(104);   \
                        }while(0)
#define MOTOR_ERROR_OFF    do{ \
                            LED_OFF(104);   \
                           }while(0)

#define TCS_ERROR_ON     do{ \
                            LED_ON(100);   \
                        }while(0)
#define TCS_ERROR_OFF    do{ \
                            LED_OFF(100);   \
                           }while(0)

#define P_ON    do{ \
                    }while(0)
#define P_OFF   do{ \
                        }while(0)

#define ABS_ON  do{ \
                LED_ON(101);    \
                    }while(0)
#ifdef LINURM_DEBUG_DIS_RATE_AND_SPEED

#define ABS_OFF

#else

#define ABS_OFF     do{ \
                    LED_OFF(101);   \
                        }while(0)

#endif
#define BLUE_KEY_ON     do{ \
                        }while(0)
#define BLUE_KEY_OFF    do{ \
                            }while(0)
#define BLUE_CON_ON     do{ \
                            }while(0)
#define BLUE_CON_OFF    do{ \
                        }while(0)

#define DADENG_ON   do{ \
                        LED_ON(98); \
                    }while(0)
#ifdef LINURM_DEBUG_DIS_RATE_AND_SPEED
#define DADENG_OFF

#else
#define DADENG_OFF  do{ \
                        LED_OFF(98);    \
                            }while(0)
#endif
#define SHIKUO_ON   do{ \
                        }while(0)
#define SHIKUO_OFF  do{ \
                                }while(0)

#define WUDENG_ON   do{ \
                        }while(0)
#define WUDENG_OFF  do{ \
                                }while(0)

#define BAT_ERROR_ON   do{ \
                                                    LED_ON(106);    \
                            }while(0)

#define BAT_ERROR_OFF  do{ \
                                                        LED_OFF(106);    \
                                    }while(0)

#define YOUZUAN_ON  do{ \
                            LED_ON(109); \
                        }while(0)

#ifdef LINURM_DEBUG_DIS_RATE_AND_SPEED
#define YOUZUAN_OFF
#else
#define YOUZUAN_OFF     do{ \
                            LED_OFF(109);   \
                                }while(0)
#endif
#define ZUOZUAN_ON  do{ \
                            LED_ON(97); \
                        }while(0)
#ifdef LINURM_DEBUG_DIS_RATE_AND_SPEED
#define ZUOZUAN_OFF

#else

#define ZUOZUAN_OFF     do{ \
                            LED_OFF(97);    \
                                }while(0)
#endif
#define DOT_LED_ON LED_ON(12)
#define DOT_LED_OFF LED_OFF(12)
#define RIGHT_DOT_LED_ON LED_ON(190)
#define RIGHT_DOT_LED_OFF LED_OFF(190)

#define KMPH_ON     do{ \
                            LED_ON(143); \
                        }while(0)
#define KMPH_OFF    do{ \
                            LED_OFF(143);   \
                         }while(0)
#define MPH_ON  do{ \
                             LED_ON(142); \
                         }while(0)
#define MPH_OFF     do{ \
                                LED_OFF(142);   \
                                    }while(0)
#define MILES_ON    do{ \
                                    LED_ON(234); \
                                }while(0)
#define MILES_OFF   do{ \
                                    LED_OFF(234);   \
                                        }while(0)
#define KM_ON   do{ \
                                        LED_ON(191); \
                                    }while(0)
#define KM_OFF  do{ \
                                        LED_OFF(191);   \
                                            }while(0)
#define FT_ON   do{ \
    LED_ON(192);   \
                                        }while(0)
#define FT_OFF  do{ \
    LED_OFF(192);   \
                                                }while(0)
#define MILES_LEFT_ON    do{ \
                                        LED_OFF(203); \
                                    }while(0)
#define MILES_LEFT_OFF   do{ \
                                        LED_OFF(203);   \
                                            }while(0)
#define KM_LEFT_ON   do{ \
                                            LED_OFF(16); \
                                        }while(0)
#define KM_LEFT_OFF  do{ \
                                            LED_OFF(16);    \
                                                }while(0)
#define FT_LEFT_ON   do{ \
                            LED_OFF(251);   \
                        }while(0)
#define FT_LEFT_OFF  do{ \
                            LED_OFF(251);   \
                            }while(0)

#define DIANCHI_ON  do{ \
                                        }while(0)
#define DIANCHI_OFF     do{ \
                                                }while(0)

#define ODO_ON  do{ \
                                LED_ON(188); \
                            }while(0)
#define ODO_OFF     do{ \
                                LED_OFF(188);   \
                                    }while(0)
#define TRIP_ON     do{ \
                                    LED_ON(189); \
                                }while(0)
#define TRIP_OFF    do{ \
                                    LED_OFF(189);   \
                                        }while(0)

#define TEMPERATURE_0   do{     \
                        }while(0)
#define TEMPERATURE_1   do{     \
                            }while(0)
#define TEMPERATURE_2   do{     \
                                }while(0)

#define TEMPERATURE_3   do{     \
                            }while(0)

#define TEMPERATURE_4   do{     \
                            }while(0)

#define TEMPERATURE_5   do{     \
                            }while(0)
#define TEMPERATURE_5_R   do{     \
                            }while(0)
#define TEMPERATURE_FAULT   do{     \
                                }while(0)
#define TEMPERATURE_FAULT_R   do{     \
                                    }while(0)

#define TEMPERATURE_OPEN_R   do{     \
                                    }while(0)

#define TEMPERATURE_OPEN   do{     \
                            }while(0)

#define MODE_P   do{     \
                        LED_ON(202); \
                        LED_ON(218); \
                        LED_ON(154); \
                        LED_ON(155); \
                        LED_ON(156); \
                        LED_ON(157); \
                        LED_OFF(158); \
                        LED_ON(159); \
                        LED_OFF(160); \
                        }while(0)

#define MODE_0   do{     \
                        LED_ON(202); \
                        LED_ON(218); \
                        LED_ON(154); \
                        LED_OFF(155); \
                        LED_ON(156); \
                        LED_ON(157); \
                        LED_ON(158); \
                        LED_ON(159); \
                        LED_ON(160); \
                            }while(0)

#define MODE_1   do{     \
                        LED_ON(202); \
                        LED_ON(218); \
                        LED_OFF(154); \
                        LED_OFF(155); \
                        LED_OFF(156); \
                        LED_OFF(157); \
                        LED_OFF(158); \
                        LED_ON(159); \
                        LED_ON(160); \
                            }while(0)
#define MODE_1_R   do{     \
                                }while(0)

#define MODE_2   do{     \
    LED_ON(202); \
                        LED_ON(218); \
                        LED_OFF(154); \
                        LED_ON(155); \
                        LED_ON(156); \
                        LED_ON(157); \
                        LED_ON(158); \
                        LED_ON(159); \
                        LED_OFF(160); \
                            }while(0)
#define MODE_3   do{     \
                        LED_ON(202); \
                        LED_ON(218); \
                        LED_OFF(154); \
                        LED_OFF(155); \
                        LED_ON(156); \
                        LED_ON(157); \
                        LED_ON(158); \
                        LED_ON(159); \
                        LED_ON(160); \
                                }while(0)
#define MODE_R   do{     \
                        LED_ON(202); \
                        LED_ON(218); \
                        LED_ON(154); \
                        LED_ON(155); \
                        LED_ON(156); \
                        LED_ON(157); \
                        LED_OFF(158); \
                        LED_ON(159); \
                        LED_ON(160); \
                                    }while(0)
#define MODE_OFF   do{     \
                            LED_OFF(202); \
                            LED_OFF(218); \
                            LED_OFF(154); \
                            LED_OFF(155); \
                            LED_OFF(156); \
                            LED_OFF(157); \
                            LED_OFF(158); \
                            LED_OFF(159); \
                            LED_OFF(160); \
                                        }while(0)

#define MODE_5   do{     \
                                        }while(0)
#define MODE_5_R   do{     \
                                            }while(0)

#define MODE_FAULT  do{     \
                                        }while(0)
#define MODE_FAULT_R   do{     \
                                            }while(0)
#define MODE_OPEN  do{     \
                            LED_ON(202);    \
                            LED_ON(218);    \
                            LED_ON(107);    \
                            LED_ON(108);    \
                            LED_ON(110);    \
                            LED_ON(111);    \
                            LED_ON(81);    \
                            LED_ON(83);    \
                            LED_ON(85);    \
                            LED_ON(87);    \
                            LED_ON(116);    \
                            LED_ON(115);    \
                            LED_ON(114);    \
                            LED_ON(113);    \
                            LED_ON(129);    \
                            LED_ON(130);    \
                            LED_ON(131);    \
                            LED_ON(132);    \
                            LED_ON(145);    \
                            LED_ON(146);    \
                            LED_ON(148);    \
                            LED_ON(149);    \
                            LED_ON(150);    \
                            LED_ON(151);    \
                            LED_ON(152);    \
                            LED_ON(153);    \
                            LED_ON(144);    \
                            LED_ON(128);    \
                            LED_ON(127);    \
                            LED_ON(126);    \
                            LED_ON(125);    \
                            LED_ON(124);    \
                            LED_OFF(102);    \
                            LED_OFF(103);    \
                            LED_ON(161);    \
                            LED_ON(162);    \
                            LED_ON(163);    \
                            LED_ON(164);    \
                            LED_ON(165);    \
                            LED_ON(166);    \
                            LED_ON(167);    \
                            LED_ON(168);    \
                            LED_ON(177);    \
                            LED_ON(178);    \
                            LED_ON(179);    \
                            LED_ON(180);    \
                            LED_ON(181);    \
                            LED_ON(182);    \
                            LED_ON(183);    \
                            LED_ON(184);    \
                            LED_ON(169);    \
                            LED_ON(185);    \
                            LED_ON(170);    \
                            LED_ON(186);    \
                            LED_ON(187);    \
                            RANGE_ON;   \
                            }while(0)

/*

            */

#define MODE_OPEN_R   do{     \
                            LED_OFF(202);    \
                            LED_OFF(218);    \
                            LED_OFF(107);    \
                            LED_OFF(108);    \
                            LED_OFF(110);    \
                            LED_OFF(111);    \
                            LED_OFF(81);    \
                            LED_OFF(83);    \
                            LED_OFF(85);    \
                            LED_OFF(87);    \
                            LED_OFF(82);    \
                            LED_OFF(84);    \
                            LED_OFF(86);    \
                            LED_OFF(65);    \
                            LED_OFF(71);    \
                            LED_OFF(50);    \
                            LED_OFF(52);    \
                            LED_OFF(53);    \
                            LED_OFF(49);    \
                            LED_OFF(51);    \
                            LED_OFF(54);    \
                            LED_OFF(33);    \
                            LED_OFF(42);    \
                            LED_OFF(34);    \
                            LED_OFF(38);    \
                            LED_OFF(40);    \
                            LED_OFF(116);    \
                            LED_OFF(115);    \
                            LED_OFF(114);    \
                            LED_OFF(113);    \
                            LED_OFF(129);    \
                            LED_OFF(130);    \
                            LED_OFF(131);    \
                            LED_OFF(132);    \
                            LED_OFF(145);    \
                            LED_OFF(146);    \
                            LED_OFF(148);    \
                            LED_OFF(149);    \
                            LED_OFF(150);    \
                            LED_OFF(151);    \
                            LED_OFF(152);    \
                            LED_OFF(153);    \
                            LED_OFF(144);    \
                            LED_OFF(128);    \
                            LED_OFF(127);    \
                            LED_OFF(126);    \
                            LED_OFF(125);    \
                            LED_OFF(124);    \
                            LED_OFF(102);    \
                            LED_OFF(103);    \
                            LED_OFF(161);    \
                            LED_OFF(177);    \
                            LED_OFF(162);    \
                            LED_OFF(178);    \
                            LED_OFF(163);    \
                            LED_OFF(179);    \
                            LED_OFF(164);    \
                            LED_OFF(180);    \
                            LED_OFF(165);    \
                            LED_OFF(181);    \
                            LED_OFF(166);    \
                            LED_OFF(182);    \
                            LED_OFF(167);    \
                            LED_OFF(183);    \
                            LED_OFF(168);    \
                            LED_OFF(184);    \
                            LED_OFF(169);    \
                            LED_OFF(185);    \
                            LED_OFF(170);    \
                            LED_OFF(186);    \
                            LED_OFF(187);    \
                            RANGE_OFF;      \
                            LED_OFF(80);    \
                            LED_OFF(79);    \
                            }while(0)

#define READY_ON    do{ \
                        LED_ON(102);    \
                        LED_ON(103);    \
                    }while(0)

#define READY_OFF   do{ \
                        LED_OFF(102);    \
                        LED_OFF(103);    \
                    }while(0)

#define BAT_FRAME_UP_ON    do{ \
                                LED_ON(82);    \
                            LED_ON(84);    \
                            LED_ON(86);    \
                            LED_ON(65);    \
                            LED_ON(71);    \
                            LED_ON(50);    \
                            LED_ON(52);    \
                            LED_ON(53);    \
                            LED_ON(79);    \
}while(0)


#define BAT_FRAME_DOWN_ON    do{ \
                            LED_ON(49);    \
                            LED_ON(51);    \
                            LED_ON(54);    \
                            LED_ON(33);    \
                            LED_ON(42);    \
                            LED_ON(34);    \
                            LED_ON(38);    \
                            LED_ON(40);    \
                            LED_ON(80);    \
                        }while(0)

#define BAT_FRAME_UP_OFF   do{ \
                                LED_OFF(82);    \
                            LED_OFF(84);    \
                            LED_OFF(86);    \
                            LED_OFF(65);    \
                            LED_OFF(71);    \
                            LED_OFF(50);    \
                            LED_OFF(52);    \
                            LED_OFF(53);    \
                            LED_OFF(79);    \
                        }while(0)
#define BAT_FRAME_DOWN_OFF   do{ \
                            LED_OFF(49);    \
                            LED_OFF(51);    \
                            LED_OFF(54);    \
                            LED_OFF(33);    \
                            LED_OFF(42);    \
                            LED_OFF(34);    \
                            LED_OFF(38);    \
                            LED_OFF(40);    \
                            LED_OFF(80);    \
                        }while(0)
#define BOOT_LED_ON     do{         \
                            GEAR_ON;    \
                            LOW_POWER_ON;   \
                            ECU_ERROR_ON; \
                            MOTOR_ERROR_ON;\
                            TCS_ERROR_ON;\
                            BAT_ERROR_ON;\
                            P_ON;   \
                            DADENG_ON;  \
                            SHIKUO_ON;  \
                            WUDENG_ON;  \
                            YOUZUAN_ON; \
                            ZUOZUAN_ON; \
                            TRIP_ON;    \
                            ODO_ON; \
                            KM_ON;  \
                            KM_LEFT_ON;  \
                            MILES_ON;   \
                            MILES_LEFT_ON;   \
                            MPH_ON; \
                            KMPH_ON;    \
                            FT_ON;  \
                            FT_LEFT_ON; \
                            DIANCHI_ON; \
                            ABS_ON; \
                            BLUE_KEY_ON;    \
                            BLUE_CON_ON; \
                            DOT_LED_ON; \
                            RIGHT_DOT_LED_ON; \
                        }while(0)

#define BOOT_LED_OFF    do{         \
                            GEAR_OFF;   \
                            LOW_POWER_OFF;  \
                            ECU_ERROR_OFF;    \
                            MOTOR_ERROR_OFF;\
                            TCS_ERROR_OFF;\
                            BAT_ERROR_OFF;\
                            P_OFF;  \
                            DADENG_OFF; \
                            SHIKUO_OFF; \
                            WUDENG_OFF; \
                            YOUZUAN_OFF;    \
                            ZUOZUAN_OFF;    \
                            TRIP_OFF;   \
                            ODO_OFF;    \
                            KM_OFF; \
                            KM_LEFT_OFF; \
                            FT_OFF; \
                            FT_LEFT_OFF; \
                            MILES_OFF;  \
                            MILES_LEFT_OFF;  \
                            MPH_OFF;    \
                            DIANCHI_OFF;    \
                            ABS_OFF;    \
                            BLUE_KEY_OFF;   \
                            DOT_LED_OFF;    \
                            RIGHT_DOT_LED_OFF;\
                        }while(0)

#define RANGE_ON    do{ \
                        LED_OFF(4);    \
                        LED_OFF(8);    \
                    }while(0)

#define RANGE_OFF   do{ \
                        LED_OFF(4);    \
                        LED_OFF(8);    \
                    }while(0)

void lock_init();
void lock_do();
void unlock_do();

extern uint8_t ctrl_d;
extern uint8_t ret_status;
extern uint8_t recoil_energy;
extern uint8_t throttle_open;



typedef struct {
    uint16_t vol;
    uint16_t cur;
    uint8_t sig;
    uint8_t status;
    uint8_t mos;
    uint8_t fault;
    uint16_t soc;
    uint16_t soh;
    uint16_t disc_cur;
    uint16_t feed_cur;
} BAT_TYPE;

extern BAT_TYPE bat_up;
extern BAT_TYPE bat_down;

extern uint8_t bat_fault;
extern uint8_t motor_fault;
extern uint8_t ecu_fault;

void range_info_init();

#ifdef __cplusplus
}
#endif

#ifdef __cplusplus
class input
{

public:
    input();
    ~input();

};
#endif



#endif
